package cn.lzm.basic.controller;

import cn.lzm.basic.dto.LoginAccountDto;
import cn.lzm.basic.dto.WeChatCodeDto;
import cn.lzm.basic.service.ILoginService;
import cn.lzm.basic.util.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private ILoginService loginService;
    @RequestMapping("/account")
    public AjaxResult loginByAccount(@RequestBody @Valid LoginAccountDto dto){
        log.info(dto.getAccount());
        Map<String, Object> token = loginService.loginByAccount(dto);
        return AjaxResult.me().success(token);

    }

    @RequestMapping("/phone")
    public AjaxResult loginByPhone(@RequestBody  LoginAccountDto dto){
        log.info(dto.getAccount());
        Map<String, Object> token = loginService.loginByPhone(dto);
        return AjaxResult.me().success(token);

    }

    @RequestMapping("/wechat")
    public AjaxResult loginByWechat(@RequestBody WeChatCodeDto dto){
        log.info(dto.getCode());
        AjaxResult token = loginService.loginByWechat(dto);
        return token;

    }

    @RequestMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WeChatCodeDto dto){
        log.info(dto.getCode());
        Map<String, Object> token = loginService.wechatBinder(dto);
        return AjaxResult.me().success(token);

    }

}
